package com.atguigu.exer2;

import java.util.*;

/**
 * 请从键盘随机输入10个整数保存到List中，并按倒序、从大
 * 到小的顺序显示出来
 */
public class NumberSort {
    public static void main(String[] args) {
        List list = new ArrayList();

        Scanner scan = new Scanner(System.in);
        System.out.print("请输入10个整数：");
        for(int i = 0;i < 10;i++) {
            list.add(scan.nextInt());
        }

        Collections.sort(list,new Comparator() {
            @Override
            public int compare(Object o1, Object o2) {
                if(o1 instanceof Integer && o2 instanceof Integer){
                    Integer i1 = (Integer) o1;
                    Integer i2 = (Integer) o2;
                    return -Integer.compare(i1,i2);
                }
                throw new RuntimeException("输入数据不匹配");
            }
        });

        Iterator iterator = list.iterator();
        while(iterator.hasNext()){
            System.out.println(iterator.next());
        }

        Collections.reverse(list);
        System.out.println(list);
    }
}
